/*
 * =====================================================================================
 *
 *       Filename:  cl_lexical_cast.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  12/11/2010 04:18:23 AM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Chen Ken (Ken), zlchen.ken@gmail.com
 *        Company:  EMC
 *
 * =====================================================================================
 */

#ifndef _CL_LEXICAL_CAST_H_
#define _CL_LEXICAL_CAST_H_

#include <sstream>

namespace neo
{
template<typename Target, typename Source>
inline Target clLexicalCast(Source arg) 
{
	std::stringstream interpreter;
	Target result;
	if( !(interpreter << arg) || !(interpreter >> result) || !(interpreter >> std::ws).eof() )
	{
		throw std::bad_cast();
	}

	return result;
}
} //neo

#endif //_CL_LEXICAL_CAST_H_ 

